package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin//跨域
@RequestMapping()
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("findAll")
    public List<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("getUserById")//只允许Get请求
    public User getUserById(User user) {
        return userService.getUserById(user);
    }

    @GetMapping("getUserByNS")
    public List<User> getUserByNS(User user) {
        return userService.getUserByNS(user);
    }

    //需求：查询 name包含"君"
    @GetMapping("User/{name}")
    public List<User> User(@PathVariable String name) {
        return userService.User(name);
    }

    //需求：查询 name包含"王"，sex=男
    //如果参数有多个，可以使用对象封装，要求参数名称与属性一致
    @GetMapping("User02/{name}/{sex}")
    public List<User> User02(User user) {
        return userService.User02(user);
    }

    @DeleteMapping("User03")
    public String deleteUser03(User user) {
        return userService.deleteUser03(user);
    }

    @DeleteMapping("user/{id}")
    public String deleteUser04(User user) {
        return userService.deleteUser03(user);
    }

    @PostMapping("/saveUser")
    public String save(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @PutMapping("/updateUser")
    public String  update(@RequestBody User user){
        return userService.updateUser(user);
    }

    @GetMapping("/select")
    public List<User> select(User user){
        //System.out.println(user);
        return userService.select(user);
    }
}
